Skip to main content
Version: 5.3.0.0

Sample Program (Password Authentication)

Sample

The following section demonstrates a sample java client that can be used to invoke a Orchestra object receiver channel. This client uses a basic password based authentication.

package test.client;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import emds.orchestra.service.ServiceCall;

/**
* This is a sample test program that demonstrates how a java programm can invoke
* a orchestra object input channel
*/

public class OrchestraClientPasswortAuth {

static String ORCHESTRA_URL = "";

final static String PARAM_FILENAME = "FILENAME";
final static String PARAM_CONTENT = "CONTENT";
final static String PARAM_STATE = "STATE";

public static void main(String[] args) throws Exception {

if (args.length != 4) {
System.out.println("Usage: OrchestraClient <Orchestra-URL> <FileToOrchestra> <mimetype> <tries>");
System.exit(1);
}

try {
ORCHESTRA_URL = args[0];

/* ***************************************************************************************
* Use the following line to add a systemwide authenticator. This method is required
* if the orchestra service channel requires digest authentication.
* ***************************************************************************************/

// Uncomment the following lines to use a systemwide authenticator
// Authenticator.setDefault(new SimpleAuthenticator("LOGIN", "testx".toCharArray()));

int tries = Integer.parseInt(args[3]);

for (int i = 0; i < tries; i++) {

/* *******************************************************
* Prepare the orchestra service call
* *******************************************************/

ServiceCall service = new ServiceCall(ORCHESTRA_URL);

/* ***************************************************************************************
* Use the following lines to enable preemptive authentication. This method can be used
* if user/password authentification is required
* ***************************************************************************************/

service.setPasswordAuthentication("test", "test".toCharArray());

/* ***************************************************************************************
* Use the following lines to enable certificate authentication. With your own
* ssl socket-factory
* ***************************************************************************************/

service.prepare();

/* *******************************************************
* Add call parameters to the service-call object
* *******************************************************/

service.addParameter(PARAM_FILENAME, args[1]);
service.addStreamParameter(PARAM_CONTENT, args[2]);

/* *******************************************************
* Write the file-content to the orchestra data stream
* *******************************************************/

writeFileToStream(args[1], service.getStream());

/* *******************************************************
* Submit the service call to orchestra and receive
* the result data
* *******************************************************/

Map<String, Object> result = service.submit();

/* *******************************************************
* Check the result data if a parameter PARAM_SATE is
* available
* *******************************************************/

if (result.containsKey(PARAM_STATE)) {
System.out.println(i + ". Orchestra-State: " + result.get(PARAM_STATE));
}
}

} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Write the given file to the output stream
*
* @param file
* @param out
* @throws IOException
*/

public static void writeFileToStream(String file, OutputStream out) throws IOException {

InputStream in = new FileInputStream(new File(file));
int datax = 0;

while ((datax = in.read()) != -1) {
out.write(datax);
}

out.close();
in.close();
}
}